<?php

namespace App\Http\Middleware;

use App\Http\Util\Tool;
use App\Http\Util\Err;
use Closure;
use Illuminate\Http\Request;

class CheckLoginStatus
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $post = $request->all();
        if(!$post['token']){
            return response()->json(['code'=>Err::TOKEN_EXPIRE[0],'msg'=>Err::TOKEN_EXPIRE[1]]);
        }
         $userInfo = json_decode(session()->get($post['token']),true);
         if(!$userInfo){
             return response()->json(['code'=>Err::TOKEN_EXPIRE[0],'msg'=>Err::TOKEN_EXPIRE[1]]);
         }
         $mid_params = ['memberId'=>$userInfo['id']];
         $request->attributes->add($mid_params);//添加参数
        return $next($request);
    }
}
